package com.universal.schedule;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MineActivity extends Activity {

	private ListView mListView;
	private ArrayList<Map<String, Object>> mDatas;
	private TextView mUserName;
	private TextView mUserPhone;
	private ImageView mImage;
	private int[] icon = { R.drawable.setup,R.drawable.praise,
	            R.drawable.time,R.drawable.exit};
	private String[] descriable = { "设置","邀请好友", "闹钟","退出"};
	private SimpleAdapter mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mine);
		findView();
		
		
		mDatas= new ArrayList<Map<String, Object>>();
		initDatas();
		mAdapter = new SimpleAdapter(this, mDatas, R.layout.mine_recycler_item, new String[]{ "image", "descriable",}, new int[]{ R.id.mine_recycler_icon, R.id.mine_recycler_text});
//	mAdapter=new SimpleAdapter(v.getContext(),mDatas);
//	mRecyclerView.setAdapter(mAdapter);
		
//	LinearLayoutManager linearLayoutManager=new LinearLayoutManager(v.getContext(),LinearLayoutManager.VERTICAL,false);
//	mRecyclerView.setLayoutManager(linearLayoutManager);
		mListView.setAdapter(mAdapter);
		mListView.setOnItemClickListener(new OnItemClickListener() {
			
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				if(position==0){ 
					Intent intent = new Intent(MineActivity.this, ClearDataActivity.class);
					startActivity(intent);
				}else if(position==1){
					Intent intent = new Intent(MineActivity.this, InviteFriendActivity.class);
				startActivity(intent);
				}else if(position==2){
					finish();
				}else if(position==3){
					final AlertDialog.Builder normalDialog = 
				            new AlertDialog.Builder(MineActivity.this);
				        normalDialog.setTitle("退出登录");
				        normalDialog.setMessage("确定退出登录?");
				        normalDialog.setPositiveButton("确定", 
				            new DialogInterface.OnClickListener() {
				            @Override
				            public void onClick(DialogInterface dialog, int which) {
				                //...To-do
				            	//System.exit(0);
								Intent intent = new Intent(MineActivity.this,LoginActivity.class);
								startActivity(intent);
				            }
				        });
				        normalDialog.setNegativeButton("取消", 
				            new DialogInterface.OnClickListener() {
				            @Override
				            public void onClick(DialogInterface dialog, int which) {
				            }
				        });
				        normalDialog.show();
				}
				else{
					Toast.makeText(MineActivity.this, "暂时尚未开放"+ position, Toast.LENGTH_SHORT).show();
				}
			}
			
		});
	}

	private void findView() {
		mListView=(ListView)findViewById(R.id.mine_recycler);
		mUserName = (TextView)findViewById(R.id.mine_user_name);
		mUserPhone = (TextView)findViewById(R.id.mine_user_phone);
		mImage = (ImageView)findViewById(R.id.profile_image1);
	}
	
	public  List<Map<String, Object>> initDatas(){        
		mDatas.clear();
        for(int i=0;i<icon.length;i++){
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("image", icon[i]);
            map.put("descriable", descriable[i]);
 

            mDatas.add(map);
       }
		return mDatas;
//    }


}
	


}
